﻿package rob.data{
	// 3D Bounding Box in World Coordinates
	
	public class BBox{
		public var min:Vect3d, max:Vect3d;
		
		public function BBox():void{
			min = new Vect3d(0,0,0);
			max = min.clone();
		}
		
		// given an array of vects/verts compute boundaries
		public function compute(a:Array):void{
			min.x = max.x = a[0].x;
			min.y = max.y = a[0].y;
			min.z = max.z = a[0].z;
			for each(var p in a){
				if(p.x < min.x) min.x = p.x;
				else if(p.x > max.x) max.x = p.x;
				if(p.y < min.y) min.y = p.y;
				else if(p.y > max.y) max.y = p.y;
				if(p.z < min.z) min.z = p.z;
				else if(p.z > max.z) max.z = p.z;
			}
		}

		public function get width():Number{return max.x - min.x;}
		public function get depth():Number{ return max.z - min.x;}
		public function get height():Number{ return max.y - min.y; }
		
		public function get center():Vert3d{ 
			return new Vert3d((max.x+min.x)/2,(max.y+min.y)/2,(max.z+min.z)/2);
		}
		
		public function toString():String{
			return "BBox: ("+min+","+max+")";
		}
	}
}